﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yq.ControllerBase.CaChe
{
   /// <summary>
    /// 本地缓存基础类型
   /// </summary>
   public abstract class ICaChe
   {
       /// <summary>
       /// 缓存名称,默认为当前类名的全路径名称
       /// </summary>
       private string _CacheName = string.Empty;
       /// <summary>
       /// 缓存名称,默认为当前类名的全路径名称
       /// </summary>
       protected string CacheName
       {
           get
           {
               if (string.IsNullOrEmpty(_CacheName))
               {
                   _CacheName = this.GetType().FullName;
               }

               return (this._CacheName);
           }
           set { this._CacheName = value; }
       }

       /// <summary>
       /// 缓存时间,单位为分钟,默认为60分钟
       /// </summary>
       private int _CacheTime = 60;
       /// <summary>
       /// 缓存时间,单位为分钟,默认为10分钟
       /// </summary>
       protected int CacheTime
       {
           get { return (this._CacheTime); }
           set { this._CacheTime = value; }
       }

       public abstract T ReadCache<T>(string key) where T :class;

       /// <summary>
       /// 清除缓存信息
       /// 仅移除缓存,不重新请求数据
       /// </summary>
       public virtual void ResetCache()
       {
           if (CacheHelper.GetCache(this.CacheName) != null)
           {
               CacheHelper.Remove(this.CacheName);
           }
       }
   }

}
